package com.example.classwork;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;

import java.util.List;

public class RateListActivity extends AppCompatActivity {
    private Handler handler;
    private ProgressBar bar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate_list);
        ListView mylist = findViewById(R.id.mylistview);
        bar = findViewById(R.id.progressBar);
        mylist.setEmptyView(bar);
    // String[] data = {"one", "tow", "three", "测试项数据"};
      // ListAdapter adapter = new ArrayAdapter<String>(this,
        //       android.R.layout.simple_list_item_1, data);
       //mylist.setAdapter(adapter);

        handler = new Handler() {
            @Override
            public void handleMessage(@NonNull Message msg) {
                if (msg.what == 5) {
                    List<String> list = (List<String>) msg.obj;
                    ListAdapter adapter = new ArrayAdapter<String>(RateListActivity.this, android.R.layout.simple_list_item_1, list);
                    mylist.setAdapter(adapter);
                }
                super.handleMessage(msg);
            }

        };
        MyTask myTask=new MyTask();
        myTask.setHandler(handler);
        Thread t = new Thread(myTask);
        t.start();
    }
}